/*新开页面功能*/
/*------------------------------------------------------------常用项目编辑、删除---------------------------------------------------------------------------------------*/
//常用项目编辑添加数据后直接保存
function addChangyongItem(obj)
{
	var edittr = $("#changyongxiangmu_table").find(".edit-status");
	var trid = $(edittr).attr("id");
	var oldstr = edittr.attr("data-info");
	var oldobj = JSON.parse(oldstr);
	var url = rootUrl + "/clidoctor/updateBdj1ByBce01AndBbx01";
	var param =
	{
	bbx01 : obj.bbx01,
	bbx01_ : oldobj.bbx01,
	bce01 : bce01
	};
	var data =
	{
		params : JSON.stringify(param)
	}
	$.when($.post(url, data)).done(function(data)
	{
		if (data.result == "Success")
		{
			$("#changyongxiangmu").trigger("click");
			//显示刚才修改的那一行；
			setTimeout(function()
			{
				$("#" + trid).addClass("edit-status").siblings().removeClass("edit-status"); //呈现编辑状态
			}, 200)

			layer.msg('修改成功',
			{
			time : 2000,
			icon : 1,
			skin : 'layui-layer-msg1'
			});
		}
		else
		{
			layer.msg('修改失败',
			{
			time : 2000,
			icon : 2,
			skin : 'layui-layer-msg2'
			});
		}

	})

}

//删除常用项目
function delChangyongItem(that)
{
	var tr = $(that).parents("tr");
	var datastr = $(tr).attr("data-info");
	var dataobj = JSON.parse(datastr);
	var text = dataobj.fname ? dataobj.fname : dataobj.bbx05;
	layer.confirm('确定要删除 ' + text,
	{
	btn :
	['确定', '取消'],
	icon : 3,
	// 按钮
	}, function()
	{
		var url = rootUrl + "/clidoctor/deleteBdj1ByBce01AndBbx01";
		var param =
		{
		bbx01 : dataobj.bbx01,
		bce01 : bce01
		};
		var data =
		{
			params : JSON.stringify(param)
		}
		$.when($.post(url, data)).done(function(data)
		{
			if (data.result == "Success")
			{
				$(tr).remove();
				layer.msg('删除成功',
				{
				time : 2000,
				icon : 1,
				skin : 'layui-layer-msg1'
				});
			}
			else
			{
				layer.msg('删除失败',
				{
				time : 2000,
				icon : 2,
				skin : 'layui-layer-msg2'
				});
			}

		})

	}, function()
	{
	});
}
/*-----------------------------------------------------------------常用项目编辑、删除 end-------------------------------------------------------------------------------------------*/
//是否启用医保用药限制提示,及医保用药限制提示是否只针对医保病人
function YibaoYongyaoXianzhi(bby01s,curTr){
	if (valueArr["p_100_105002_420"]=="1"){  //启用医保用药限制提示
		if (valueArr["p_9999_9999_114"]=="1"){//只针对医保病人
			if($("#patient_bdp02").text()!="自费"){
				XianzhiTixing(bby01s,curTr);
			}
			
		}else{
			XianzhiTixing(bby01s,curTr);
		}
		
	}
}
function XianzhiTixing(bby01s,curTr){
	var iaa01 = valueArr["p_100_105002_421"];
	var url = rootUrl+"/clidoctor/selectDataByScriptId";
	var para = {
			ID:10000024,
			paramStr:'{iaa01 :"'+iaa01+'",bby01s:"'+bby01s+'"}'
			};
	$.when($.get(url, para)).done(function(data) {
		debugger;
		if(data.result == "Success"){
			if(data.list.length>0){
				var list = data.list[0]
				if(list.iah42 == "是"){
					var text = '项目  "'+list.bby05+'" 有医保限制内容："'+list.iah44+'" 请确认是否符合限制';
					layer.confirm(text,
							{
							btn : ['确定', '取消'],
							icon : 3,
							// 按钮
							}, function()
							{
								var data_veh1 = { veh02:1}
								curTr.data(data_veh1);
								layer.msg('保存成功',
										{
										time : 2000,
										icon : 1,
										skin : 'layui-layer-msg1'
										});
								
							}, function()
							{
								var data_veh1 = { veh02:0};
								curTr.data(data_veh1);
							});
				}
			}else{
				
			}
		}
	})
}

function  getVeh02(arr){
	var def = $.Deferred();
	var Veh02s;
	var vaf01s = getBby01s(arr)
	var iaa01 = valueArr["p_100_105002_421"];
	var url = rootUrl+"/clidoctor/selectDataByScriptId";
	var para = {};
	var paramStr = {};
	paramStr.vaf01s = "'{"+vaf01s+"}'";
	para.paramStr = JSON.stringify(paramStr);
	para.ID = "10000027";
	$.when($.get(url, para)).done(function(data) {
		debugger;
		if(data.result == "Success"){
			 def.resolve(data.list);
				
		}else{
			def.reject();
		}
	})
	 return def.promise();
}
function getBby01s(arr){
	var vaf01s=[]
	for(var i =0; i <arr.length;i++){
		vaf01s.push(arr[i].vaf01);
	}
	vaf01s = vaf01s.join(",");
	return vaf01s;
}

//新开医嘱警告提示（非药品）
function remaindByBbx01(obj){
	var bbx01= obj.bbx01,isManualTrigger=obj.isManualTrigger,activeAdviceInputId=obj.activeAdviceInputId;
	var urlCom = rootUrl + "/basicinformationquery/basequery";
	var param16 = {params:JSON.stringify({sqlId:10000049,bbx01:bbx01})};
	$.ajax({
		url:urlCom,
		type: "get",
		data:param16,
		dataType:'json',
		async: true,
		success:function(data)
		{
			debugger;
			if(data.list[0] && data.list[0].bbx43){
				var msg = data.list[0].bbx43;
				var bbx01index = layer.alert(msg,
							{icon : 0,
					yes:function(){
						layer.close(bbx01index);
						if(isManualTrigger || isManualTrigger == undefined){
							manualTriggerByparam(activeAdviceInputId);
						}
					},
					cancel: function(index, layero){ 
						if(isManualTrigger || isManualTrigger == undefined){
							manualTriggerByparam(activeAdviceInputId);
						}
					} 
				});
			}else{
				if(isManualTrigger || isManualTrigger == undefined){
					manualTriggerByparam(activeAdviceInputId);
				}
			}
						
			
		}
	})
}
//根据员工职业类别范围，默认处方类型
function setPreCategory(){
	debugger;
	var preType =1;
	var urlCom = rootUrl+"/basicinformationquery/basequery";
	var params = {params:JSON.stringify({sqlId:10000050,bce01:bce01})};
	$.ajax({
		url:urlCom,
		type: "get",
		data:params,
		dataType:'json',
		async: false,
		success:function(data)
		{
			if(data){
				var temp = data.list[0];
				if(temp&&(temp.abe01=='14'||temp.abe01==14))
				{
					preType  = 3;
				}
			}

		}
	})
	return preType;
}

//常用方案--个人
function getPersonalFangan0(bbx15,id){
	debugger;
	var urlCom = rootUrl+"/basicinformationquery/basequery";
	var text = '\'%%\'';
	var params = {params:JSON.stringify({sqlId:10000053,bce01:bce01,bbx15:bbx15,bck01:bck01,text:text})};
	$.when($.get(urlCom, params)).done(function(data){
		if(data){
			laytplUrl(myurl+"/module/zhiliao_geren.html",data,function(data,html){
				$("#"+id).html(html);
				
			})
		}
	})
}
//常用方案--科室
function getPersonalFangan1(bbx15,id){
	debugger;
	var urlCom = rootUrl+"/basicinformationquery/basequery";
	var text1='';
	if($("#fanganjiansuoText").length>0){
		text1 = $("#fanganjiansuoText").val();
		var reg= /^[A-Za-z]+$/; //判断是字母
		if (reg.test(text1)){
			text1 = text1.toLowerCase();
		}
	}
	var text = '\'%'+text1+'%\'';
	var params = {params:JSON.stringify({sqlId:10000053,bce01:bce01,bbx15:1,bck01:bck01,text:text})};
	var params1 = {params:JSON.stringify({sqlId:10000053,bce01:bce01,bbx15:2,bck01:bck01,text:text})};
	$.when($.get(urlCom, params),$.get(urlCom, params1)).done(function(data,data1){
		var list = data[0].list;
		var list1 = data1[0].list;
		list = $.merge(list, list1);      
		if(list.length>0){
			var obj={};
			obj.list =list; 
			laytplUrl(myurl+"/module/zhiliao_geren.html",obj,function(data,html){
				$("#"+id).find(".main-table-container").html(html);
			})
		}else{
			$("#"+id).find(".main-table-container").html("<span>没有符合的数据</span>");
		}
	})
}

//方案回显判断是不是同一个医嘱单bef29
function IsAddSimilarTab(dataObj){
	var actives = activeTabParam();
	var $last_tr = $("#"+actives.tableId).find("tr").last();
	var dstr = $last_tr.attr("data-info");
	if(dstr){
		var dobj = JSON.parse(dstr);
		var bef29 = dobj.bef29;
		if(dataObj.bef29 != bef29){  //不同的医嘱单，新增一个同类医嘱单
			$("#new_similar").trigger("click");
		}
	}
}
//获取浏览器参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}

